class MessageType:
    alert = 'alert'
    primary = 'primary'
    secondary = 'secondary'
    success = 'success'
    danger = 'danger'
    warning = 'warning'
    info = 'info'
    light = 'light'
    dark = 'dark'


class Message:
    type = ''
    content = ''

    def __init__(self, msg_content='', msg_type=''):
        self.content = msg_content
        self.type = msg_type

    @property
    def serialize(self):
        """serialize Object to Json Dict"""
        obj = {
            'content': self.content,
            'type': self.type
        }
        return obj


def set_global_msg(request, msg_text='', msg_type=''):
    """设置全局消息"""
    msg = Message(msg_text, msg_type)
    request.session['global_msg'] = msg.serialize


def get_global_msg(request):
    """获取全局消息"""
    if 'global_msg' in request.session:
        msg = request.session['global_msg']
        del request.session['global_msg']
        return msg
    else:
        return None
